<html>
<head><meta charset="utf-8"><title>ignore original target in custom codegen? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ignore.20original.20target.20in.20custom.20codegen.3F.html">ignore original target in custom codegen?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244100208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ignore%20original%20target%20in%20custom%20codegen%3F/near/244100208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ignore.20original.20target.20in.20custom.20codegen.3F.html#244100208">(Jun 28 2021 at 04:10)</a>:</h4>
<p>So i am writing a custom rustc backend for NVVM IR (a subset of llvm ir for cuda gpu kernels), hoping to show off a basic kernel soon. But i am kind of stuck on something im not sure how to handle. NVVM only accepts <code>nvptx64-nvidia-cuda</code> and <code>nvptx-nvidia-cuda</code> as its targets and will error if you give it anything else. It also does not accept any ABI annotations, everything is generated using the ptx ABI. So i was thinking, should i just ignore the original target for the session and generate everything for nvptx, or should i not ignore the original target and error if its not nvptx?</p>
<p>Both approaches have pros and cons, ignoring the original target:</p>
<ul>
<li>means users can cfg for arches just fine without needing to do some weird feature/env trickery</li>
<li>
<p>makes it easier to potentially compile the kernels using "normal" rustc to run them on the cpu (a future goal id like to explore)</p>
</li>
<li>
<p>makes it way easier for me to miss things that are target/abi specific in the codegen (i pull a lot of code from rustc_codegen_llvm) which may potentially result in unsoundness</p>
</li>
<li>makes it harder to cfg for the gpu backend (although users could just target nvptx as normal then cfg for that, this isnt stopping that)</li>
</ul>
<p>forcing nvptx:</p>
<ul>
<li>leaves no room for error in translating codegen code</li>
<li>potentially might cause <span aria-label="bug" class="emoji emoji-1f41b" role="img" title="bug">:bug:</span>s for target/nvvm mismatches, for example, the target data layout and the accepted data layouts for nvvm for some reason appear different</li>
</ul>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>